﻿<?php
/**
 * fastPayTradeMergePay	普通订单支付跳转	接口
 * User: azhi
 * Date: 2016/11/24
 * Time: 14:34
 */

function testResponse(){

    $config = $GLOBALS['config'];
    $user = $GLOBALS['user'];


    $objReq = new \yijipay\message\request\FastPayTradeMergePayRequest();

    //请求公共部分
    $objReq->setReturnUrl(getReturnUrl());
    $objReq->setNotifyUrl(getNotifyUrl());
    //partnerId默认yijipay\config.php中已经配置
    //$objReq->setPartnerId($config['partnerId']); 
    $objReq->setMerchOrderNo("T" . genOrderNo());
    $objReq->setOrderNo("RID".genOrderNo());
    //signType默认MD5
    $objReq->setSignType("MD5");
    //$objReq->setContext("");
    
    //构建交易参数
    $item1 = genTradeInfo($user);
    $objReq->setBuyerOrgName("买家PHP");
    $objReq->setBuyerRealName("买家PHP");
    $objReq->setBuyerUserId($user['buyer_uid_yiji']);
    $objReq->setOutUserId($user['buyer_id']);
    $objReq->setTradeInfo([$item1]);

    //收银台参数
//	$objReq->setPaymentType("QUICKPAY");
    $objReq->setUserTerminalType("PC");

    echo "================request: preSignStr：";
    echo "<br/>". \yijipay\SignHelper::getPreSignStr($objReq);

    //构建请求
    $client = new \yijipay\YijiPayClient($config);
    

    //方式1：重定向到易极付页面
//    $html = $client->pageExecute($objReq);
//    echo $html;
//    exit;

    //方式2: 获取重定向URL
    $response = $client->execute($objReq);
    $resp = json_decode($response);
    if($client->verify($response) && $resp->success){
        //================================
        // 此处填写创建成功的代码
        //================================

    }else{
        //================================
        // 此处填写创建成功的代码
        //====
        throw new Exception($resp->resultMessage);
    }

    exit;

}


function genTradeInfo($user){
    //构建订单1
    $item1 = new yijipay\message\request\dto\TradeInfo();

    //$item1->setPactNo("");
    $item1->setMerchOrderNo("M" . genOrderNo());
    $item1->setTradeName("货单手镯");
    $item1->setSellerUserId($user['seller_uid_yiji']);
    $item1->setSellerOrgName($user['seller_name']);

    $item1->setTradeAmount("100.00");
    $item1->setGoodsName("手镯SZYN01");
    //$item1->setGoodsTypeCode("");
    //$item1->setGoodsTypeName("");
    $item1->setCurrency("CNY");

    $item1->setMemo("进货");
    //$item1->setShareProfits("");
    //$item1->setAutoCloseDuration(0);

    return $item1;
}
